<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>git项目管理总结 | mozihao</title><meta name="keywords" content="Git项目开发版本管理"><meta name="author" content="mozihao"><meta name="copyright" content="mozihao"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="开发中的运用一般的在多人开发的过程中，一开机我们开始需要先git pull拉取一下远程的代码，再进行编写 当我们一顿操作写完代码之后 基本操作12345678910111213&#x2F;&#x2F;先查看一下我们的修改的代码的文件，是否是正确git status&#x2F;&#x2F;下面将想要提交的文件add一遍，下面的 ‘.‘ 表示修改的所有文件，当然你也可以一个一个的add，看一下上一步的">
<meta property="og:type" content="article">
<meta property="og:title" content="git项目管理总结">
<meta property="og:url" content="https://mo_zi_hao.gitee.io/blog/posts/33426/index.html">
<meta property="og:site_name" content="mozihao">
<meta property="og:description" content="开发中的运用一般的在多人开发的过程中，一开机我们开始需要先git pull拉取一下远程的代码，再进行编写 当我们一顿操作写完代码之后 基本操作12345678910111213&#x2F;&#x2F;先查看一下我们的修改的代码的文件，是否是正确git status&#x2F;&#x2F;下面将想要提交的文件add一遍，下面的 ‘.‘ 表示修改的所有文件，当然你也可以一个一个的add，看一下上一步的">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://gitee.com/mo_zi_hao/picsBed/raw/master/image/000.jpg">
<meta property="article:published_time" content="2021-08-29T15:22:14.596Z">
<meta property="article:modified_time" content="2021-08-29T15:22:14.596Z">
<meta property="article:author" content="mozihao">
<meta property="article:tag" content="Git项目开发版本管理">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://gitee.com/mo_zi_hao/picsBed/raw/master/image/000.jpg"><link rel="shortcut icon" href="/blog/img/favicon.png"><link rel="canonical" href="https://mo_zi_hao.gitee.io/blog/posts/33426/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/blog/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/blog/',
  algolia: undefined,
  localSearch: {"path":"search.xml","languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: {"defaultEncoding":2,"translateDelay":0,"msgToTraditionalChinese":"繁","msgToSimplifiedChinese":"簡"},
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    jQuery: 'https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js',
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/js/jquery.justifiedGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/css/justifiedGallery.min.css'
    },
    fancybox: {
      js: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js',
      css: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: true,
  isanchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = { 
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2021-08-29 23:22:14'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    })(window)</script><link rel="stylesheet" type="text/css" href="./css/iconfont.css" media="all"><meta name="generator" content="Hexo 5.4.2"><link rel="alternate" href="/blog/atom.xml" title="mozihao" type="application/atom+xml">
</head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="author-avatar"><img class="avatar-img" src="https://gitee.com/mo_zi_hao/picsBed/raw/master/image/%E6%B5%B7%E8%B4%BC008.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data"><div class="data-item is-center"><div class="data-item-link"><a href="/blog/archives/"><div class="headline">文章</div><div class="length-num">24</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/blog/tags/"><div class="headline">标签</div><div class="length-num">16</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/blog/categories/"><div class="headline">分类</div><div class="length-num">11</div></a></div></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/blog/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/blog/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/blog/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/blog/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/blog/about/"><i class="fa-fw fas fa-heart"></i><span> 前端知识思维导图</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://gitee.com/mo_zi_hao/picsBed/raw/master/image/000.jpg')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/blog/">mozihao</a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/blog/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/blog/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/blog/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/blog/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/blog/about/"><i class="fa-fw fas fa-heart"></i><span> 前端知识思维导图</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">git项目管理总结</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2021-08-29T15:22:14.596Z" title="发表于 2021-08-29 23:22:14">2021-08-29</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2021-08-29T15:22:14.596Z" title="更新于 2021-08-29 23:22:14">2021-08-29</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/blog/categories/Git/">Git</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">4.4k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>15分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="git项目管理总结"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h3 id="开发中的运用"><a href="#开发中的运用" class="headerlink" title="开发中的运用"></a>开发中的运用</h3><p>一般的在多人开发的过程中，一开机我们开始需要先git pull拉取一下远程的代码，再进行编写</p>
<p>当我们一顿操作写完代码之后</p>
<h4 id="基本操作"><a href="#基本操作" class="headerlink" title="基本操作"></a>基本操作</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;&#x2F;先查看一下我们的修改的代码的文件，是否是正确</span><br><span class="line">git status</span><br><span class="line">&#x2F;&#x2F;下面将想要提交的文件add一遍，下面的 ‘.‘ 表示修改的所有文件，当然你也可以一个一个的add，看一下上一步的路径将 ’.‘ 替换为对应的路径就好了</span><br><span class="line">git add .</span><br><span class="line">&#x2F;&#x2F;再查看一下状态，是否是预期add的文件，一般的我都会去vscode再次确认自己所修改的东西是否正确，会不会有什么测试代码没去除的</span><br><span class="line">git status</span><br><span class="line">&#x2F;&#x2F;下边将代码保存到本地，下面的注释可能大家的规范也不太一致，我是用fix代表的修复bug，只举个例子，注释清晰，才好复查每个提交的记录</span><br><span class="line">git commit -m &quot;fix：修复什么什么&quot;</span><br><span class="line">&#x2F;&#x2F;拉取一下远程代码，有冲突则解决冲突</span><br><span class="line">git pull</span><br><span class="line">（如果有冲突解决冲突保存文件之后要再add一次和commit一次）：git add .   ----&gt;   git commit -m &quot;chore:解决冲突&quot;</span><br><span class="line">&#x2F;&#x2F;上传到远程仓库</span><br><span class="line">git push</span><br></pre></td></tr></table></figure>



<h4 id="合并分支"><a href="#合并分支" class="headerlink" title="合并分支"></a>合并分支</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;&#x2F;先查看一下远程分支</span><br><span class="line">git branch -r</span><br><span class="line">&#x2F;&#x2F;先切换分支到想要合并的目标分支(在上一步复制一下目标分支名)</span><br><span class="line">git checkout 分支名</span><br><span class="line">&#x2F;&#x2F;拉去一下最新的代码</span><br><span class="line">git pull</span><br><span class="line">&#x2F;&#x2F;如果是将目标分支合并到自己的开发分支,这时就需要切回自己的开发分支了</span><br><span class="line">git checkout 分支名</span><br><span class="line">&#x2F;&#x2F;合并目标分支</span><br><span class="line">git merge 分支名</span><br><span class="line">&#x2F;&#x2F;然后此时会弹出合并注释输入英文 :wq 然后回车</span><br><span class="line">&#x2F;&#x2F;如果有冲突,则解决冲突跟上面的基本操作一样解决冲突然后保存再add一次然后commit</span><br><span class="line">&#x2F;&#x2F;最后一步如果需要提交到远程的话</span><br><span class="line">git push</span><br></pre></td></tr></table></figure>



<h4 id="如果再修改着一个bug还没修完-但是你需要去处理另外一个紧急的bug-此时你改的东西还不想commit"><a href="#如果再修改着一个bug还没修完-但是你需要去处理另外一个紧急的bug-此时你改的东西还不想commit" class="headerlink" title="如果再修改着一个bug还没修完,但是你需要去处理另外一个紧急的bug,此时你改的东西还不想commit"></a>如果再修改着一个bug还没修完,但是你需要去处理另外一个紧急的bug,此时你改的东西还不想commit</h4><p>解决方法:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;&#x2F;将代码暂存再栈里面</span><br><span class="line">git stash save &quot;注释&quot;</span><br><span class="line">&#x2F;&#x2F;此时你会发现修改的代码的文件全没了,不用担心,只是存起来了,执行下面命令行查看是否真的存在栈里面</span><br><span class="line">git stash list</span><br><span class="line">&#x2F;&#x2F;此时你就可以切换分支去修改你的紧急的bug了</span><br><span class="line">&#x2F;&#x2F;然后修改完后你想继续修改原来的bug了,先查看栈信息,查看一下自己的是存在哪个索引里(因为可能你同事也存了)</span><br><span class="line">git stash list </span><br><span class="line">&#x2F;&#x2F;下面分两种情况:</span><br><span class="line">&#x2F;&#x2F;1.(如果只有你自己一个存了) 直接  git stash pop     &#x2F;&#x2F;恢复到工作区</span><br><span class="line">git stash pop</span><br><span class="line">&#x2F;&#x2F;2.(如果出现多条,还有其他同事存了),那么就要看看你的是存再哪个索引里,下面我以再索引 0 为例子 &#x2F;&#x2F;恢复到工作区</span><br><span class="line">git stash pop stash@&#123;0&#125;</span><br><span class="line">&#x2F;&#x2F;上面恢复到工作区后,就就又可以看到你之前修改的代码了</span><br><span class="line">&#x2F;&#x2F;下面,如果你不想要了,想再重新写也行,但是你要清理一下你存的那个信息,下面选一个</span><br><span class="line">git stash drop [stash_id] 删除一个存储的进度，如果不指定stash_id，则默认删除最新的存储进度</span><br><span class="line">git stash clear 删除所有栈</span><br></pre></td></tr></table></figure>

<h4 id="版本回滚和回退"><a href="#版本回滚和回退" class="headerlink" title="版本回滚和回退"></a>版本回滚和回退</h4><p>回退： reset      //回退到某次提交，然后某次提交之后的都会没掉</p>
<p>回滚： revert   //撤销中间的某一次的提交，某次提交之后的提交还会存在</p>
<p>版本回退在开发中都是一件比较慎重的事，除非还没提交到远程的，不到万不得已的情况下我们一般不怎么想回退</p>
<p>碰到有以下几种情况：</p>
<p>在多人开发中，我们一般都会分需求开发，然后再合并到同一个分支上</p>
<h5 id="1-如果只是在自己的开发分支，可以使用reset回退或者revert回滚版本"><a href="#1-如果只是在自己的开发分支，可以使用reset回退或者revert回滚版本" class="headerlink" title="1.如果只是在自己的开发分支，可以使用reset回退或者revert回滚版本"></a>1.如果只是在自己的开发分支，可以使用reset回退或者revert回滚版本</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">revert：</span><br><span class="line">&#x2F;&#x2F;我们先查看当前分支提交日志</span><br><span class="line">git log</span><br><span class="line">&#x2F;&#x2F;通过提交日志，我们可以找到对应的提交记录的commit_id,然后执行revert撤销掉那个commit_id的提交</span><br><span class="line">git revert commit_id</span><br><span class="line">&#x2F;&#x2F;如果你想取消这次 revert 可以执行 取消回滚:   git revert --abort</span><br><span class="line">&#x2F;&#x2F;最后一步 </span><br><span class="line">git push</span><br><span class="line"></span><br><span class="line">reset:</span><br><span class="line">&#x2F;&#x2F;同上，查看当前分支提交日志</span><br><span class="line">git log</span><br><span class="line">&#x2F;&#x2F;然后找到对应的commit_id，回退到对应的commit_id的提交</span><br><span class="line">git reset --hard commit_id</span><br><span class="line">&#x2F;&#x2F;最后一步 </span><br><span class="line">git push</span><br></pre></td></tr></table></figure>



<h5 id="2-如果你回退-回滚的是合并的记录，那么这里就需要注意了"><a href="#2-如果你回退-回滚的是合并的记录，那么这里就需要注意了" class="headerlink" title="2.如果你回退 / 回滚的是合并的记录，那么这里就需要注意了"></a>2.如果你回退 / 回滚的是合并的记录，那么这里就需要注意了</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">revert：（慎重使用revert撤回合并记录）</span><br><span class="line">&#x2F;&#x2F;我们先查看当前分支提交日志</span><br><span class="line">git log</span><br><span class="line">&#x2F;&#x2F;通过提交日志，我们可以找到对应的提交记录的commit_id,然后执行revert撤销掉那个commit_id的提交</span><br><span class="line">&#x2F;&#x2F;！！！注意：那么如果你后面在次合并，但这次修改涉及到上次回退涉及到的代码时，再次合并那部分代码即使再合并过来也不会复现，如果需要拿回之前部分的代码，并进行合并那么则需要revert上一次的回滚了</span><br><span class="line">git revert commit_id</span><br><span class="line">&#x2F;&#x2F;如果你想取消这次 revert 可以执行 取消回滚:   git revert --abort</span><br><span class="line">&#x2F;&#x2F;最后一步 </span><br><span class="line">git push</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">reset:</span><br><span class="line">&#x2F;&#x2F;同上，查看当前分支提交日志</span><br><span class="line">git log</span><br><span class="line">&#x2F;&#x2F;然后找到对应的commit_id，回退到对应的commit_id的提交</span><br><span class="line">git reset --hard commit_id</span><br><span class="line">&#x2F;&#x2F;最后一步 </span><br><span class="line">git push</span><br><span class="line">&#x2F;&#x2F;如果你回退的那次提交后面还有同事合并过，那么你就需要通知一下你的同事，叫他们再合并过来一次</span><br></pre></td></tr></table></figure>



<h4 id="cherry-pick将指定某次或者某几次提交提交到某个分支——修复某些bug，如果你有一些什么其他私有化的项目分支也需要修复"><a href="#cherry-pick将指定某次或者某几次提交提交到某个分支——修复某些bug，如果你有一些什么其他私有化的项目分支也需要修复" class="headerlink" title="cherry-pick将指定某次或者某几次提交提交到某个分支——修复某些bug，如果你有一些什么其他私有化的项目分支也需要修复"></a>cherry-pick将指定某次或者某几次提交提交到某个分支——修复某些bug，如果你有一些什么其他私有化的项目分支也需要修复</h4><p>可以使用cherry-pick</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;&#x2F;首先还是地查看提交日志</span><br><span class="line">git log --all   &#x2F;&#x2F;查看所有分支的历史</span><br><span class="line"></span><br><span class="line">对于多分支的代码库，将特定的几个提交移到另一个分支是常见需求</span><br><span class="line">git cherry-pick &lt;commitHash&gt; 将指定的提交commitHash，应用于当前分支</span><br><span class="line">git cherry-pick feature 表示将feature分支的最近一次提交，转移到当前分支</span><br><span class="line">git cherry-pick &lt;HashA&gt; &lt;HashB&gt; 转移多个commit到当前分支</span><br><span class="line">git cherry-pick A..B 转移从 A 到 B 的所有提交. 注意不包含提交 A 如果要包含提交 A使用git cherry-pick A^..B</span><br><span class="line"></span><br><span class="line">（想回到 cherry-pick 之前，那么可以使用 git cherry-pick --abort ）</span><br></pre></td></tr></table></figure>



<h4 id="rabase变基"><a href="#rabase变基" class="headerlink" title="rabase变基"></a>rabase变基</h4><p>（变基在很多分支开发的情况下，可以用于多分支开发提交变成一条直线的提交，方便查看）</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git rebase 分支名</span><br></pre></td></tr></table></figure>

<p>下面以master为例子：</p>
<p>git rebase master</p>
<p><img src="https://gitee.com/mo_zi_hao/picsBed/raw/master/image/clipboard200.png" alt="rabase"></p>
<h4 id="git从某个提交检出新分支"><a href="#git从某个提交检出新分支" class="headerlink" title="git从某个提交检出新分支"></a>git从某个提交检出新分支</h4><p>从某一个commit开始创建本地分支 </p>
<p>1、git log 查看提交</p>
<p>2、通过checkout 跟上commitId 即可创建制定commit之前的本地分支 </p>
<p>git checkout commitId -b 本地新branchName </p>
<p>上传到远程服务器 </p>
<p>依然通过push 跟上你希望的远程新分支名字即可 </p>
<p>git push origin HEAD:远程新branchName </p>
<h4 id="解决git-pull-push每次都需要输入密码问题"><a href="#解决git-pull-push每次都需要输入密码问题" class="headerlink" title="解决git pull/push每次都需要输入密码问题"></a>解决git pull/push每次都需要输入密码问题</h4><ol>
<li><p>git bash进入你的项目目录，输入：</p>
</li>
<li><p>git config –global credential.helper store</p>
</li>
</ol>
<p>然后你会在你本地生成一个文本，上边记录你的账号和密码。当然这些你可以不用关心。</p>
<p>然后你使用上述的命令配置好之后，再操作一次git pull，然后它会提示你输入账号密码，这一次之后就不需要再次输入密码了</p>
<h4 id="切换远程仓库"><a href="#切换远程仓库" class="headerlink" title="切换远程仓库"></a>切换远程仓库</h4><h6 id="如果A是已有仓库，B是新建立的空仓库。"><a href="#如果A是已有仓库，B是新建立的空仓库。" class="headerlink" title="如果A是已有仓库，B是新建立的空仓库。"></a>如果A是已有仓库，B是新建立的空仓库。</h6><p>1、在本地拉一下（git clone）A仓库的代码，或者是git pull 下最新的代码。</p>
<p>2、git remote? ?# 查看本地连接的有哪些 远程仓库，默认是 origin</p>
<p>3、git remote add origin2(这个名字随便起) master? ?#?这里是在本地添加一个新的远程连接</p>
<p>4、git remote set-url origin2 B仓库的地址? ?#?这里是新加个远程连接 设置上url地址</p>
<p>5、在A的本地仓库? git push origin2 dev:master? ?#?origin2 是你想push上哪个远程库，dev 是你想push哪个分支，master 是push到远程的哪个分支。? ? 这个命令执行以后要输密码，记得是新仓库的密码。</p>
<h6 id="远程仓库已经存在master分支"><a href="#远程仓库已经存在master分支" class="headerlink" title="远程仓库已经存在master分支"></a>远程仓库已经存在master分支</h6><p>远程master的代码是无用的并且可以使用强推</p>
<p>//添加仓库</p>
<p>git remote add origin &lt;仓库地址&gt;</p>
<p>//强制push本地master分支到远端的master分支</p>
<p>git push origin master:master -f</p>
<h6 id="远程仓库未创建分支"><a href="#远程仓库未创建分支" class="headerlink" title="远程仓库未创建分支"></a>远程仓库未创建分支</h6><p>//添加仓库</p>
<p>git remote add origin &lt;仓库地址&gt;</p>
<p>//push本地master分支新建远端master分支</p>
<p>git push origin master:master</p>
<p>—另一个方法：使用镜像（还没使用过）</p>
<p>git push –mirror http://…(目标仓库地址)</p>
<h3 id="查看git账号名及邮箱"><a href="#查看git账号名及邮箱" class="headerlink" title="查看git账号名及邮箱"></a>查看git账号名及邮箱</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">git config user.name</span><br><span class="line">git config user.email</span><br></pre></td></tr></table></figure>



<h3 id="修改全局配置git-账号及邮箱"><a href="#修改全局配置git-账号及邮箱" class="headerlink" title="修改全局配置git 账号及邮箱"></a>修改全局配置git 账号及邮箱</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">git config --global user.name &quot;账号名&quot;</span><br><span class="line">git config --global user.email &quot;邮箱名&quot;</span><br></pre></td></tr></table></figure>



<h3 id="配置局部git账号"><a href="#配置局部git账号" class="headerlink" title="配置局部git账号"></a>配置局部git账号</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">git config user.name &quot;账号名&quot;</span><br><span class="line">git config user.email &quot;邮箱名&quot;</span><br></pre></td></tr></table></figure>



<h4 id="如果开始输入密码错误"><a href="#如果开始输入密码错误" class="headerlink" title="如果开始输入密码错误"></a>如果开始输入密码错误</h4><p>remote: HTTP Basic: Access denied</p>
<p>fatal: Authentication failed for ‘http://********</p>
<p><img src="https://gitee.com/mo_zi_hao/picsBed/raw/master/image/clipboard22.png" alt="错误信息"></p>
<p>解决方案：</p>
<p>git config –system –unset credential.helper</p>
<p>之后再进行git操作时，弹出用户名密码窗口，输入即可</p>
<h3 id="查看分支历史（提交日志）"><a href="#查看分支历史（提交日志）" class="headerlink" title="查看分支历史（提交日志）"></a>查看分支历史（提交日志）</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">查看所有分支的历史 git log --all   图形化查看 git log --all --graph</span><br><span class="line"></span><br><span class="line">查看当前分支的历史 git log</span><br><span class="line"></span><br><span class="line">​	查看当前分支历史-简洁 git log --oneline</span><br><span class="line"></span><br><span class="line">​	查看所有分支历史-简洁 git log --oneline --all</span><br><span class="line"></span><br><span class="line">​	查看所有分支历史的近几个历史（此处4个） git log --oneline --all -n4</span><br><span class="line"></span><br><span class="line">查看某个文件的历史  git log --all --full-history -- package-lock.json    &#x2F;&#x2F;例如package-lock.json文件</span><br></pre></td></tr></table></figure>



<h3 id="查看分支"><a href="#查看分支" class="headerlink" title="查看分支"></a>查看分支</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">查看所有本地分支 git branch</span><br><span class="line">查看远程所有分支 git branch -r</span><br><span class="line">查看所有分支 git branch --all </span><br></pre></td></tr></table></figure>



<h3 id="创建本地分支"><a href="#创建本地分支" class="headerlink" title="创建本地分支"></a>创建本地分支</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git branch 分支名</span><br></pre></td></tr></table></figure>

<h4 id="创建分支并切换到该分支"><a href="#创建分支并切换到该分支" class="headerlink" title="创建分支并切换到该分支"></a>创建分支并切换到该分支</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git checkout -b 分支名</span><br></pre></td></tr></table></figure>



<h4 id="在创建新的分支进行提交代码"><a href="#在创建新的分支进行提交代码" class="headerlink" title="在创建新的分支进行提交代码"></a>在创建新的分支进行提交代码</h4><p>我们新建分支的时候，不能直接git push上去，只能通过下面这样</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git push --set-upstream origin  分支名</span><br></pre></td></tr></table></figure>

<h3 id="删除分支"><a href="#删除分支" class="headerlink" title="删除分支"></a>删除分支</h3><p>git push origin :dev  # 删除远程dev分支，危险命令哦</p>
<p># 下面两条是删除本地分支</p>
<p>git checkout master  # 切换到master分支</p>
<p>git branch -d dev  # 删除本地dev分支</p>
<h3 id="add添加到git管理暂存区"><a href="#add添加到git管理暂存区" class="headerlink" title="add添加到git管理暂存区"></a>add添加到git管理暂存区</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">git add 文件名</span><br><span class="line">git add .   &#x2F;&#x2F;暂存所有修改的文件到暂存区</span><br></pre></td></tr></table></figure>



<h3 id="status查看git管理文件状态"><a href="#status查看git管理文件状态" class="headerlink" title="status查看git管理文件状态"></a>status查看git管理文件状态</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git status</span><br></pre></td></tr></table></figure>





<h3 id="fetch更新远程分支列表"><a href="#fetch更新远程分支列表" class="headerlink" title="fetch更新远程分支列表"></a>fetch更新远程分支列表</h3><p>一般我用的git fetch 比较多</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">git fetch</span><br><span class="line">git remote update origin --prune</span><br><span class="line">git remote update origin -p</span><br></pre></td></tr></table></figure>



<h3 id="pull拉取远程代码"><a href="#pull拉取远程代码" class="headerlink" title="pull拉取远程代码"></a>pull拉取远程代码</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git pull</span><br></pre></td></tr></table></figure>



<h4 id="git-pull-和-git-fetch的区别"><a href="#git-pull-和-git-fetch的区别" class="headerlink" title="git pull 和 git fetch的区别"></a>git pull 和 git fetch的区别</h4><p>git pull表示拉取更新本地的远程的分支，并拉取到最新的代码到本地，而git fetch只是拉取远程的分支跟新本地远程的分支</p>
<h3 id="commit暂存更改"><a href="#commit暂存更改" class="headerlink" title="commit暂存更改"></a>commit暂存更改</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git commit -m &quot;注释&quot;</span><br></pre></td></tr></table></figure>

<p>清理暂存区的更改 </p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git reset --hard</span><br></pre></td></tr></table></figure>



<h4 id="修改最后一次注释"><a href="#修改最后一次注释" class="headerlink" title="修改最后一次注释"></a>修改最后一次注释</h4><p>git commit –amend</p>
<p>出现有注释的界面（你的注释应该显示在第一行）， 输入i进入修改模式，修改好注释后，按Esc键 退出编辑模式，输入:wq保存并退出。</p>
<h3 id="diff对比两个commit之间的差异"><a href="#diff对比两个commit之间的差异" class="headerlink" title="diff对比两个commit之间的差异"></a>diff对比两个commit之间的差异</h3><p>git diff <commit_id_1> <commit_id_2></p>
<h3 id="push提交本地分支到远程"><a href="#push提交本地分支到远程" class="headerlink" title="push提交本地分支到远程"></a>push提交本地分支到远程</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">git push</span><br><span class="line"></span><br><span class="line">git push origin 本地分支名:远程分支名（最好远程分支与本地分支同名）</span><br></pre></td></tr></table></figure>



<h3 id="revert回滚"><a href="#revert回滚" class="headerlink" title="revert回滚"></a>revert回滚</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">git revert commit_id 可以撤销某个commit提交，撤销会产生一个新的提交</span><br><span class="line"></span><br><span class="line">&#x2F;&#x2F;取消回滚</span><br><span class="line">git revert --abort</span><br></pre></td></tr></table></figure>



<h3 id="reset回退"><a href="#reset回退" class="headerlink" title="reset回退"></a>reset回退</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git reset --hard commitId</span><br></pre></td></tr></table></figure>





<h3 id="stash暂存入队列栈"><a href="#stash暂存入队列栈" class="headerlink" title="stash暂存入队列栈"></a>stash暂存入队列栈</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">git stash(场景：不想提交当前本地修改，但需要切分支修bug)</span><br><span class="line">1.git stash 保存当前分支内容 入信息栈</span><br><span class="line">2.git stash save &quot;注释&quot;  &#x2F;&#x2F;添加注释</span><br><span class="line">2.git stash list  &#x2F;&#x2F;显示保存进度的列表</span><br><span class="line">3.git stash pop &#x2F;&#x2F;恢复最新的进度到工作区</span><br><span class="line">4.git stash pop stash@&#123;1&#125; &#x2F;&#x2F;恢复指定进度到工作区。stash_id是通过git stash list命令得到的</span><br><span class="line">5.git stash apply &#x2F;&#x2F;除了不删除恢复的进度之外，其余的git stash pop命令一样</span><br><span class="line">6.git stash drop [stash_id] 删除一个存储的进度，如果不指定stash_id，则默认删除最新的存储进度</span><br><span class="line">7.git stash clear 删除所有栈</span><br></pre></td></tr></table></figure>



<h3 id="cherry-pick"><a href="#cherry-pick" class="headerlink" title="cherry-pick"></a>cherry-pick</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">cherry-pick（场景：指定某几次提交到某个分支）</span><br><span class="line">对于多分支的代码库，将特定的几个提交移到另一个分支是常见需求</span><br><span class="line">git cherry-pick &lt;commitHash&gt; 将指定的提交commitHash，应用于当前分支</span><br><span class="line">git cherry-pick feature 表示将feature分支的最近一次提交，转移到当前分支</span><br><span class="line">git cherry-pick &lt;HashA&gt; &lt;HashB&gt; 转移多个commit</span><br><span class="line">git cherry-pick A..B 转移从 A 到 B 的所有提交. 注意不包含提交 A 如果要包含提交 A使用git cherry-pick A^..B</span><br><span class="line"></span><br><span class="line">（想回到 cherry-pick 之前，那么可以使用 git cherry-pick --abort ）</span><br></pre></td></tr></table></figure>



<h3 id="rabase变基-1"><a href="#rabase变基-1" class="headerlink" title="rabase变基"></a>rabase变基</h3><p>（变基在很多分支开发的情况下，可以用于多分支开发提交变成一条直线的提交，方便查看）    </p>
<p>git rebase master</p>
<p><img src="https://gitee.com/mo_zi_hao/picsBed/raw/master/image/clipboard200.png" alt="rabase"></p>
<h3 id="Git管理规范"><a href="#Git管理规范" class="headerlink" title="Git管理规范"></a>Git管理规范</h3><h4 id="方案一"><a href="#方案一" class="headerlink" title="方案一"></a>方案一</h4><p>采用类git-flow形式进行分支管理，分支类型主要分为<code>master</code>、<code>develop</code>、<code>release</code>、<code>bugfix</code>、<code>feature</code>。</p>
<blockquote>
<p><code>master</code> - 主干稳定分支，bugfix分支都必须从此分支检出，并在release、hotfix发布后，将release、hotfix合并到master归档；</p>
<p><code>hotfix</code> - 生产环境缺陷修复分支，用于热修复线上紧急bug的分支，由主干分支检出，再合并master归档；</p>
<p><code>release</code> - uat与发版分支，基于master分支检出，将需要迭代的需求和缺陷等分支合并到该分支，等到功能测试通过合并到master后，删除当前分支</p>
<p><code>develop</code> - 开发与测试分支，将开发完的需求或缺陷merge到此分支进行测试环境测试；</p>
<p><code>feature</code> - 功能分支，开发接到需求任务，需基于master分支检出，等到功能确定开发完成方可合并到develop分支，测试通过后，将该分支合并到release发版分支，上线一周后删除该分支，以免无用分支过多。</p>
</blockquote>
<p>开发流程示例：</p>
<ul>
<li>开发者从<code>master</code>分支检出个人的本地<code>feature</code>分支进行开发</li>
<li>若功能存在协同开发，则应将<code>feature</code>分支提交到远端，所有功能相关提交到远端<code>feature</code></li>
<li>功能开发完成后，将<code>feature</code>分支合并到<code>develop</code>分支上</li>
<li>等待测试完成，并且版本发布成功后，应该将<code>feature</code>分支删除</li>
<li><code>release</code>分支发布成功后，合并到<code>master</code>分支归档,再将<code>release</code>分支删除</li>
<li>待下一版本需求确定，循环上述操作</li>
</ul>
<h4 id="方案二"><a href="#方案二" class="headerlink" title="方案二"></a>方案二</h4><p>该方案为方案一的简化版，适用于迭代周期短的项目</p>
<blockquote>
<p><code>master</code> - 归档分支，项目完成后代码归档到该分支；</p>
<p><code>hotfix</code> - 生产环境缺陷修复分支，用于热修复线上紧急bug的分支；</p>
<p><code>release</code> - uat与发版分支，将需要迭代的需求和缺陷等分支合并到该分支</p>
<p><code>develop</code> - 开发与测试分支，将开发完的需求或缺陷merge到此分支进行测试环境测试；</p>
<p><code>feature</code> - 功能分支，开发接到需求任务，需基于develop或者release分支检出，等到功能确定开发完成方开发自测通过可合并到develop分支测试验证。</p>
</blockquote>
<p>开发流程示例：</p>
<ul>
<li>开发者从<code>develop</code>分支检出个人的本地<code>feature</code>分支进行开发</li>
<li>若功能存在协同开发，则应将<code>feature</code>分支提交到远端，所有功能相关提交到远端<code>feature</code></li>
<li>功能开发完成后，将<code>feature</code>分支合并到<code>develop</code>分支上</li>
<li>等待测试完成，并且版本发布成功后，应该将<code>feature</code>分支删除</li>
<li>待下一版本需求确定，循环上述操作</li>
</ul>
<hr>
<p>分支命名规范:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">release分支:release&#x2F;版本号_发布日期，如release&#x2F;v1.0.0_20200515   </span><br><span class="line">feature分支:feature&#x2F;功能_创建日期（建议），如feature&#x2F;news_20200515</span><br><span class="line">hotfix分支:hotfix&#x2F;版本号_发布日期，如hotfix&#x2F;v1.0.0_20200515 </span><br><span class="line">&#96;</span><br></pre></td></tr></table></figure>

<h4 id="commit规范"><a href="#commit规范" class="headerlink" title="commit规范"></a>commit规范</h4><p>前缀规范：commit提交时，需根据当前提交、修改内容的性质加上对应前缀，便于后续溯源。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">chore: 构建过程或辅助工具的变动</span><br><span class="line">feat : 新功能 </span><br><span class="line">fix : 修复bug  </span><br><span class="line">docs : 文档改变</span><br><span class="line">style : 代码格式改变</span><br><span class="line">refactor : 某个已有功能重构</span><br><span class="line">perf : 性能优化</span><br><span class="line">test : 增加测试</span><br><span class="line">revert: 撤销上一次的 commit </span><br></pre></td></tr></table></figure>

<p>提交时机：每天工作结束之前，需要把当天要提交的代码内容至少提交一次</p>
<p>提交审查：如时间允许，提交代码前应经过同行审查，注明提交信息（审批人：XXX-具体需求名称）才能提交</p>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="mailto:undefined">mozihao</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://mo_zi_hao.gitee.io/blog/posts/33426/">https://mo_zi_hao.gitee.io/blog/posts/33426/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://mo_zi_hao.gitee.io/blog" target="_blank">mozihao</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/blog/tags/Git%E9%A1%B9%E7%9B%AE%E5%BC%80%E5%8F%91%E7%89%88%E6%9C%AC%E7%AE%A1%E7%90%86/">Git项目开发版本管理</a></div><div class="post_share"><div class="social-share" data-image="https://gitee.com/mo_zi_hao/picsBed/raw/master/image/000.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/social-share.js/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/blog/posts/43904/"><img class="prev-cover" src="https://gitee.com/mo_zi_hao/picsBed/raw/master/image/4560.jpg" onerror="onerror=null;src='/blog/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">pc、h5项目踩坑</div></div></a></div><div class="next-post pull-right"><a href="/blog/posts/16107/"><img class="next-cover" src="https://gitee.com/mo_zi_hao/picsBed/raw/master/image/%E6%B5%B7%E8%B4%BC4.jpg" onerror="onerror=null;src='/blog/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">hexo发布命令</div></div></a></div></nav></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="card-info-avatar is-center"><img class="avatar-img" src="https://gitee.com/mo_zi_hao/picsBed/raw/master/image/%E6%B5%B7%E8%B4%BC008.jpg" onerror="this.onerror=null;this.src='/blog/img/friend_404.gif'" alt="avatar"/><div class="author-info__name">mozihao</div><div class="author-info__description">if you risk nothing,then you risk anthing</div></div><div class="card-info-data"><div class="card-info-data-item is-center"><a href="/blog/archives/"><div class="headline">文章</div><div class="length-num">24</div></a></div><div class="card-info-data-item is-center"><a href="/blog/tags/"><div class="headline">标签</div><div class="length-num">16</div></a></div><div class="card-info-data-item is-center"><a href="/blog/categories/"><div class="headline">分类</div><div class="length-num">11</div></a></div></div><a class="button--animated" id="card-info-btn" target="_blank" rel="noopener" href="https://gitee.com/mo_zi_hao"><i class="iconfont icon-gitee-fill-round"></i><span>我的Gitee</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://gitee.com/mo_zi_hao" target="_blank" title="Gitee"><i class="fab iconfont icon-gitee-fill-round"></i></a><a class="social-icon" href="https://github.com/mmCrazy" target="_blank" title="Github"><i class="fab fa-github"></i></a><a class="social-icon" href="https://blog.csdn.net/xiaomohhh?spm=1001.2101.3001.5343" target="_blank" title="CSDN"><i class="fab iconfont icon-csdn"></i></a><a class="social-icon" href="https://gitee.com/mo_zi_hao/picsBed/raw/master/image/qrcode_for_gh_d35478eda980_430.jpg" target="_blank" title="公众号"><i class="fab iconfont icon-weixingongzhonghao"></i></a><a class="social-icon" href="mailto:747304031@qq.com" target="_blank" title="Email"><i class="fas fa-envelope"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn card-announcement-animation"></i><span>公告</span></div><div class="announcement_content">如文章中有哪些错漏，欢迎各位前端的大佬与我交流并指正，谢谢!!</br>邮箱：747304031@qq.com</br>公众号：一起写前端bug</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%BC%80%E5%8F%91%E4%B8%AD%E7%9A%84%E8%BF%90%E7%94%A8"><span class="toc-number">1.</span> <span class="toc-text">开发中的运用</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%9F%BA%E6%9C%AC%E6%93%8D%E4%BD%9C"><span class="toc-number">1.1.</span> <span class="toc-text">基本操作</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%90%88%E5%B9%B6%E5%88%86%E6%94%AF"><span class="toc-number">1.2.</span> <span class="toc-text">合并分支</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%A6%82%E6%9E%9C%E5%86%8D%E4%BF%AE%E6%94%B9%E7%9D%80%E4%B8%80%E4%B8%AAbug%E8%BF%98%E6%B2%A1%E4%BF%AE%E5%AE%8C-%E4%BD%86%E6%98%AF%E4%BD%A0%E9%9C%80%E8%A6%81%E5%8E%BB%E5%A4%84%E7%90%86%E5%8F%A6%E5%A4%96%E4%B8%80%E4%B8%AA%E7%B4%A7%E6%80%A5%E7%9A%84bug-%E6%AD%A4%E6%97%B6%E4%BD%A0%E6%94%B9%E7%9A%84%E4%B8%9C%E8%A5%BF%E8%BF%98%E4%B8%8D%E6%83%B3commit"><span class="toc-number">1.3.</span> <span class="toc-text">如果再修改着一个bug还没修完,但是你需要去处理另外一个紧急的bug,此时你改的东西还不想commit</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E7%89%88%E6%9C%AC%E5%9B%9E%E6%BB%9A%E5%92%8C%E5%9B%9E%E9%80%80"><span class="toc-number">1.4.</span> <span class="toc-text">版本回滚和回退</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#1-%E5%A6%82%E6%9E%9C%E5%8F%AA%E6%98%AF%E5%9C%A8%E8%87%AA%E5%B7%B1%E7%9A%84%E5%BC%80%E5%8F%91%E5%88%86%E6%94%AF%EF%BC%8C%E5%8F%AF%E4%BB%A5%E4%BD%BF%E7%94%A8reset%E5%9B%9E%E9%80%80%E6%88%96%E8%80%85revert%E5%9B%9E%E6%BB%9A%E7%89%88%E6%9C%AC"><span class="toc-number">1.4.1.</span> <span class="toc-text">1.如果只是在自己的开发分支，可以使用reset回退或者revert回滚版本</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#2-%E5%A6%82%E6%9E%9C%E4%BD%A0%E5%9B%9E%E9%80%80-%E5%9B%9E%E6%BB%9A%E7%9A%84%E6%98%AF%E5%90%88%E5%B9%B6%E7%9A%84%E8%AE%B0%E5%BD%95%EF%BC%8C%E9%82%A3%E4%B9%88%E8%BF%99%E9%87%8C%E5%B0%B1%E9%9C%80%E8%A6%81%E6%B3%A8%E6%84%8F%E4%BA%86"><span class="toc-number">1.4.2.</span> <span class="toc-text">2.如果你回退 &#x2F; 回滚的是合并的记录，那么这里就需要注意了</span></a></li></ol></li><li class="toc-item toc-level-4"><a class="toc-link" href="#cherry-pick%E5%B0%86%E6%8C%87%E5%AE%9A%E6%9F%90%E6%AC%A1%E6%88%96%E8%80%85%E6%9F%90%E5%87%A0%E6%AC%A1%E6%8F%90%E4%BA%A4%E6%8F%90%E4%BA%A4%E5%88%B0%E6%9F%90%E4%B8%AA%E5%88%86%E6%94%AF%E2%80%94%E2%80%94%E4%BF%AE%E5%A4%8D%E6%9F%90%E4%BA%9Bbug%EF%BC%8C%E5%A6%82%E6%9E%9C%E4%BD%A0%E6%9C%89%E4%B8%80%E4%BA%9B%E4%BB%80%E4%B9%88%E5%85%B6%E4%BB%96%E7%A7%81%E6%9C%89%E5%8C%96%E7%9A%84%E9%A1%B9%E7%9B%AE%E5%88%86%E6%94%AF%E4%B9%9F%E9%9C%80%E8%A6%81%E4%BF%AE%E5%A4%8D"><span class="toc-number">1.5.</span> <span class="toc-text">cherry-pick将指定某次或者某几次提交提交到某个分支——修复某些bug，如果你有一些什么其他私有化的项目分支也需要修复</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#rabase%E5%8F%98%E5%9F%BA"><span class="toc-number">1.6.</span> <span class="toc-text">rabase变基</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#git%E4%BB%8E%E6%9F%90%E4%B8%AA%E6%8F%90%E4%BA%A4%E6%A3%80%E5%87%BA%E6%96%B0%E5%88%86%E6%94%AF"><span class="toc-number">1.7.</span> <span class="toc-text">git从某个提交检出新分支</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E8%A7%A3%E5%86%B3git-pull-push%E6%AF%8F%E6%AC%A1%E9%83%BD%E9%9C%80%E8%A6%81%E8%BE%93%E5%85%A5%E5%AF%86%E7%A0%81%E9%97%AE%E9%A2%98"><span class="toc-number">1.8.</span> <span class="toc-text">解决git pull&#x2F;push每次都需要输入密码问题</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%88%87%E6%8D%A2%E8%BF%9C%E7%A8%8B%E4%BB%93%E5%BA%93"><span class="toc-number">1.9.</span> <span class="toc-text">切换远程仓库</span></a><ol class="toc-child"><li class="toc-item toc-level-6"><a class="toc-link" href="#%E5%A6%82%E6%9E%9CA%E6%98%AF%E5%B7%B2%E6%9C%89%E4%BB%93%E5%BA%93%EF%BC%8CB%E6%98%AF%E6%96%B0%E5%BB%BA%E7%AB%8B%E7%9A%84%E7%A9%BA%E4%BB%93%E5%BA%93%E3%80%82"><span class="toc-number">1.9.0.1.</span> <span class="toc-text">如果A是已有仓库，B是新建立的空仓库。</span></a></li><li class="toc-item toc-level-6"><a class="toc-link" href="#%E8%BF%9C%E7%A8%8B%E4%BB%93%E5%BA%93%E5%B7%B2%E7%BB%8F%E5%AD%98%E5%9C%A8master%E5%88%86%E6%94%AF"><span class="toc-number">1.9.0.2.</span> <span class="toc-text">远程仓库已经存在master分支</span></a></li><li class="toc-item toc-level-6"><a class="toc-link" href="#%E8%BF%9C%E7%A8%8B%E4%BB%93%E5%BA%93%E6%9C%AA%E5%88%9B%E5%BB%BA%E5%88%86%E6%94%AF"><span class="toc-number">1.9.0.3.</span> <span class="toc-text">远程仓库未创建分支</span></a></li></ol></li></ol></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%9F%A5%E7%9C%8Bgit%E8%B4%A6%E5%8F%B7%E5%90%8D%E5%8F%8A%E9%82%AE%E7%AE%B1"><span class="toc-number">2.</span> <span class="toc-text">查看git账号名及邮箱</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BF%AE%E6%94%B9%E5%85%A8%E5%B1%80%E9%85%8D%E7%BD%AEgit-%E8%B4%A6%E5%8F%B7%E5%8F%8A%E9%82%AE%E7%AE%B1"><span class="toc-number">3.</span> <span class="toc-text">修改全局配置git 账号及邮箱</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E9%85%8D%E7%BD%AE%E5%B1%80%E9%83%A8git%E8%B4%A6%E5%8F%B7"><span class="toc-number">4.</span> <span class="toc-text">配置局部git账号</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%A6%82%E6%9E%9C%E5%BC%80%E5%A7%8B%E8%BE%93%E5%85%A5%E5%AF%86%E7%A0%81%E9%94%99%E8%AF%AF"><span class="toc-number">4.1.</span> <span class="toc-text">如果开始输入密码错误</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%9F%A5%E7%9C%8B%E5%88%86%E6%94%AF%E5%8E%86%E5%8F%B2%EF%BC%88%E6%8F%90%E4%BA%A4%E6%97%A5%E5%BF%97%EF%BC%89"><span class="toc-number">5.</span> <span class="toc-text">查看分支历史（提交日志）</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%9F%A5%E7%9C%8B%E5%88%86%E6%94%AF"><span class="toc-number">6.</span> <span class="toc-text">查看分支</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%88%9B%E5%BB%BA%E6%9C%AC%E5%9C%B0%E5%88%86%E6%94%AF"><span class="toc-number">7.</span> <span class="toc-text">创建本地分支</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%88%9B%E5%BB%BA%E5%88%86%E6%94%AF%E5%B9%B6%E5%88%87%E6%8D%A2%E5%88%B0%E8%AF%A5%E5%88%86%E6%94%AF"><span class="toc-number">7.1.</span> <span class="toc-text">创建分支并切换到该分支</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%9C%A8%E5%88%9B%E5%BB%BA%E6%96%B0%E7%9A%84%E5%88%86%E6%94%AF%E8%BF%9B%E8%A1%8C%E6%8F%90%E4%BA%A4%E4%BB%A3%E7%A0%81"><span class="toc-number">7.2.</span> <span class="toc-text">在创建新的分支进行提交代码</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%88%A0%E9%99%A4%E5%88%86%E6%94%AF"><span class="toc-number">8.</span> <span class="toc-text">删除分支</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#add%E6%B7%BB%E5%8A%A0%E5%88%B0git%E7%AE%A1%E7%90%86%E6%9A%82%E5%AD%98%E5%8C%BA"><span class="toc-number">9.</span> <span class="toc-text">add添加到git管理暂存区</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#status%E6%9F%A5%E7%9C%8Bgit%E7%AE%A1%E7%90%86%E6%96%87%E4%BB%B6%E7%8A%B6%E6%80%81"><span class="toc-number">10.</span> <span class="toc-text">status查看git管理文件状态</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#fetch%E6%9B%B4%E6%96%B0%E8%BF%9C%E7%A8%8B%E5%88%86%E6%94%AF%E5%88%97%E8%A1%A8"><span class="toc-number">11.</span> <span class="toc-text">fetch更新远程分支列表</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#pull%E6%8B%89%E5%8F%96%E8%BF%9C%E7%A8%8B%E4%BB%A3%E7%A0%81"><span class="toc-number">12.</span> <span class="toc-text">pull拉取远程代码</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#git-pull-%E5%92%8C-git-fetch%E7%9A%84%E5%8C%BA%E5%88%AB"><span class="toc-number">12.1.</span> <span class="toc-text">git pull 和 git fetch的区别</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#commit%E6%9A%82%E5%AD%98%E6%9B%B4%E6%94%B9"><span class="toc-number">13.</span> <span class="toc-text">commit暂存更改</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E4%BF%AE%E6%94%B9%E6%9C%80%E5%90%8E%E4%B8%80%E6%AC%A1%E6%B3%A8%E9%87%8A"><span class="toc-number">13.1.</span> <span class="toc-text">修改最后一次注释</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#diff%E5%AF%B9%E6%AF%94%E4%B8%A4%E4%B8%AAcommit%E4%B9%8B%E9%97%B4%E7%9A%84%E5%B7%AE%E5%BC%82"><span class="toc-number">14.</span> <span class="toc-text">diff对比两个commit之间的差异</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#push%E6%8F%90%E4%BA%A4%E6%9C%AC%E5%9C%B0%E5%88%86%E6%94%AF%E5%88%B0%E8%BF%9C%E7%A8%8B"><span class="toc-number">15.</span> <span class="toc-text">push提交本地分支到远程</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#revert%E5%9B%9E%E6%BB%9A"><span class="toc-number">16.</span> <span class="toc-text">revert回滚</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#reset%E5%9B%9E%E9%80%80"><span class="toc-number">17.</span> <span class="toc-text">reset回退</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#stash%E6%9A%82%E5%AD%98%E5%85%A5%E9%98%9F%E5%88%97%E6%A0%88"><span class="toc-number">18.</span> <span class="toc-text">stash暂存入队列栈</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#cherry-pick"><span class="toc-number">19.</span> <span class="toc-text">cherry-pick</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#rabase%E5%8F%98%E5%9F%BA-1"><span class="toc-number">20.</span> <span class="toc-text">rabase变基</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Git%E7%AE%A1%E7%90%86%E8%A7%84%E8%8C%83"><span class="toc-number">21.</span> <span class="toc-text">Git管理规范</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%96%B9%E6%A1%88%E4%B8%80"><span class="toc-number">21.1.</span> <span class="toc-text">方案一</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%96%B9%E6%A1%88%E4%BA%8C"><span class="toc-number">21.2.</span> <span class="toc-text">方案二</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#commit%E8%A7%84%E8%8C%83"><span class="toc-number">21.3.</span> <span class="toc-text">commit规范</span></a></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/blog/posts/1/" title="无题"><img src="https://gitee.com/mo_zi_hao/picsBed/raw/master/image/%E6%B5%B7%E8%B4%BC4.jpg" onerror="this.onerror=null;this.src='/blog/img/404.jpg'" alt="无题"/></a><div class="content"><a class="title" href="/blog/posts/1/" title="无题">无题</a><time datetime="2022-06-05T05:20:17.974Z" title="发表于 2022-06-05 13:20:17">2022-06-05</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/posts/36549/" title="编写可维护的JavaScript (代码习惯)"><img src="https://gitee.com/mo_zi_hao/picsBed/raw/master/image/%E6%B5%B7%E8%B4%BC4.jpg" onerror="this.onerror=null;this.src='/blog/img/404.jpg'" alt="编写可维护的JavaScript (代码习惯)"/></a><div class="content"><a class="title" href="/blog/posts/36549/" title="编写可维护的JavaScript (代码习惯)">编写可维护的JavaScript (代码习惯)</a><time datetime="2022-03-19T03:12:42.624Z" title="发表于 2022-03-19 11:12:42">2022-03-19</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/posts/23125/" title="gitlab-cicd"><img src="https://gitee.com/mo_zi_hao/picsBed/raw/master/image/745.jpg" onerror="this.onerror=null;this.src='/blog/img/404.jpg'" alt="gitlab-cicd"/></a><div class="content"><a class="title" href="/blog/posts/23125/" title="gitlab-cicd">gitlab-cicd</a><time datetime="2021-12-20T14:00:59.661Z" title="发表于 2021-12-20 22:00:59">2021-12-20</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/posts/449/" title="前端js基础"><img src="https://gitee.com/mo_zi_hao/picsBed/raw/master/image/26&amp;gp=0.jpg" onerror="this.onerror=null;this.src='/blog/img/404.jpg'" alt="前端js基础"/></a><div class="content"><a class="title" href="/blog/posts/449/" title="前端js基础">前端js基础</a><time datetime="2021-08-29T15:22:14.600Z" title="发表于 2021-08-29 23:22:14">2021-08-29</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/posts/35506/" title="微信小程序"><img src="https://gitee.com/mo_zi_hao/picsBed/raw/master/image/1234.jpg" onerror="this.onerror=null;this.src='/blog/img/404.jpg'" alt="微信小程序"/></a><div class="content"><a class="title" href="/blog/posts/35506/" title="微信小程序">微信小程序</a><time datetime="2021-08-29T15:22:14.600Z" title="发表于 2021-08-29 23:22:14">2021-08-29</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2023 By mozihao</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="translateLink" type="button" title="简繁转换">繁</button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div id="local-search"><div class="search-dialog"><div class="search-dialog__title" id="local-search-title">本地搜索</div><div id="local-input-panel"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div></div><hr/><div id="local-search-results"></div><span class="search-close-button"><i class="fas fa-times"></i></span></div><div id="search-mask"></div></div><div><script src="/blog/js/utils.js"></script><script src="/blog/js/main.js"></script><script src="/blog/js/tw_cn.js"></script><script src="https://cdn.jsdelivr.net/npm/vanilla-lazyload/dist/lazyload.iife.min.js"></script><script src="/blog/js/search/local-search.js"></script><div class="js-pjax"></div><script id="click-heart" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/click-heart.min.js" async="async" mobile="false"></script><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.js"></script><script src="https://cdn.jsdelivr.net/gh/metowolf/MetingJS@1.2/dist/Meting.min.js"></script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>